
#ifndef NETBASE_CONNECTOR_H
#define NETBASE_CONNECTOR_H

// sys
#include <memory>
#include <functional>
// mine
#include "util.h"

struct sockaddr;
struct event_base;

namespace net_base {
class NetBase;
class TcpSession;
typedef std::shared_ptr<TcpSession> TcpSessionPtr;

class Connector {
 public:
  typedef std::function<void (int sock_ec, TcpSessionPtr)> ConnCB;

  void Connect(const char* ip, uint16_t port, const ConnCB& cb);

  void Connect(const char* ip_port, const ConnCB& cb);

 private:
  friend class NetBase;
  Connector(event_base* evbase) : evbase_(evbase) {}

  void Connect(sockaddr* sa, int socklen, const ConnCB& cb);

  NONCOPYABLE(Connector);
  event_base* evbase_;
};

typedef std::unique_ptr<Connector> ConnectorPtr;
} // namespace net_base

#endif // NETBASE_CONNECTOR_H

